Skip to content

Conversation

@deepsleep-v3
Copy link

  1. “Switch Working Directory”(暂只有en_US翻译)

先讲一个小故事,我电脑之前C:空间太少,重装系统了,资料被format了,我转移了我的MC资料到我的U盘。但!我没转移我的hmcl.json,所以,VersionSetting也无了。到最后,我启动MC的时候,资源包、模组都丢了,一看,没开“各版本隔离”,于是,deepsleep-v3像是下定了某种决心,他马上就fork了HMCL-dev/HMCL,并且clone到他的电脑……

所以我就把这个弹窗做出来了,由于个人精力原因,暂只翻译了en_US。原理是HMCLGameLauncher生成options.txt的函数(generateOptionsTxt)里getRunDirectory()时先检测repository是否instanceof HMCLGameRepository,再创建变量,再检测:

Files.exists(Path.of(HMCLRepository.getVersionRoot(version.getId()).toString(), "resourcepacks")) ||
Files.exists(Path.of(HMCLRepository.getVersionRoot(version.getId()).toString(), "saves")) ||
Files.exists(Path.of(HMCLRepository.getVersionRoot(version.getId()).toString(), "mods")) ||
Files.exists(Path.of(HMCLRepository.getVersionRoot(version.getId()).toString(), "shaderpacks")) || 
Files.exists(Path.of(HMCLRepository.getVersionRoot(version.getId()).toString(), "crash-report"))

(代码写的有点烂,请见谅😳)
2. 修复文档的一些语法错误
起因是我在准备提交37a03fc时,发现JavaDoc写了个:

// org.jackhuang.hmcl.game.HMCLGameRepository,getLocalVersionSetting(String) → VersionSetting的文档。
/**
* Get the version setting for version id.
*
* @param id version id
* @return corresponding version setting, null if the version has no its own version setting.
*/

(原句)
限定词(determiner)和物主代词(possessive pronoun)不能一起用!
就顺手修了,修成了:

// org.jackhuang.hmcl.game.HMCLGameRepository,getLocalVersionSetting(String) → VersionSetting的文档。
/**
* Get the version setting for version id.
*
* @param id version id
* @return corresponding version setting, null if the version does not have its own version setting.
*/

谁叫我爱MC,爱HMCL呢~

Added a confirmation dialog when unexpected folders (resourcepacks, saves, mods, shaderpacks, crash-report) are detected in the version root, prompting the user to switch to 'Isolated' mode. Updated I18N.properties with new dialog strings for this feature.
Replaces manual string concatenation with Path.of() using varargs for directory checks in the ROOT_FOLDER case, improving code readability and reliability.
Added logic to process the user's selection from the working directory switch alert dialog, updating the game directory type or returning the appropriate directory based on the chosen button.
## 问题描述
在后台线程中直接调用JavaFX的Alert组件会导致`IllegalStateException: Not on FX application thread`异常,影响程序稳定性。

## 修改内容
- 将原有的直接Alert调用包装在`Platform.runLater()`中,确保UI操作在JavaFX应用程序线程执行
- 使用`CompletableFuture`在JavaFX线程和非JavaFX线程之间传递用户选择结果
- 保持原有的业务逻辑和对话框选项不变
- 添加异常处理,在对话框异常时使用默认值继续执行

## 技术细节
1. 创建`CompletableFuture<ButtonData>`用于接收用户选择
2. 在`Platform.runLater()`中:
   - 创建Confirmation类型的Alert对话框
   - 设置三个按钮选项:是、否、仅本次启动
   - 使用`showAndWait()`等待用户响应
   - 将用户选择的按钮数据传递给CompletableFuture
3. 在后台线程中使用`future.get()`阻塞等待用户选择
4. 根据按钮数据执行相应的目录设置逻辑

## 影响范围
- 修复启动器在非JavaFX线程中询问工作目录切换的问题
- 确保线程安全的同时保持原有功能不变
- 提升程序在多线程环境下的稳定性

## 测试要点
✅ 在后台线程中调用此代码段能正常显示对话框
✅ 对话框的三个按钮功能与之前一致
✅ 异常情况下能使用默认值继续执行
✅ 不会出现线程阻塞或死锁问题

## 关联问题
修复了在多线程环境下可能导致的UI崩溃问题
@deepsleep-v3 deepsleep-v3 changed the title 为HMCL启动时添加“Switch Working Directory”并修复文档的一些语法错误 feat+fix:为HMCL启动时添加“Switch Working Directory”并修复文档的一些语法错误 Jan 19, 2026
Copy link
Member

@burningtnt burningtnt left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

粗略的(在没有真正看代码逻辑的情况下)看了一眼,我认为你这里有一堆问题需要改动。

此外,简体中文和繁体中文的翻译是必须的。如果你不能熟练使用繁体中文,可使用机器翻译提供初稿,并注明需要社区成员在 PR 合并前检查润色。

@deepsleep-v3
Copy link
Author

粗略的(在没有真正看代码逻辑的情况下)看了一眼,我认为你这里有一堆问题需要改动。

此外,简体中文和繁体中文的翻译是必须的。如果你不能熟练使用繁体中文,可使用机器翻译提供初稿,并注明需要社区成员在 PR 合并前检查润色。

√ 已解决

Copy link
Contributor

@3gf8jv4dv 3gf8jv4dv left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

说实话,这个弹窗不是太美观,也不适配深色模式。可否改成下面列出的 PR 中更新的形式?

download.speed.kibibyte_per_second=%.1f KiB/s
download.speed.megabyte_per_second=%.1f MiB/s

Dialog.this_launch_only.button=This Launch only
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Suggested change
Dialog.this_launch_only.button=This Launch only
Dialog.this_launch_only.button=This launch only

launcher.crash.java_internal_error=Hello Minecraft! Launcher has encountered a fatal error because your Java is corrupted. Please uninstall your Java and download a suitable Java <a href="https://bell-sw.com/pages/downloads/#downloads">here</a>.
launcher.crash.hmcl_out_dated=Hello Minecraft! Launcher has encountered a fatal error! Your launcher is outdated. Please update your launcher!
launcher.update_java=Please update your Java version.
launcher.info.switch_working_directory.title=Would you like to switch the Working Directory?
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Suggested change
launcher.info.switch_working_directory.title=Would you like to switch the Working Directory?
launcher.info.switch_working_directory.title=Instance files detected

launcher.update_java=Please update your Java version.
launcher.info.switch_working_directory.title=Would you like to switch the Working Directory?
# %1$s = java.io.File.separator, %2$s = version root (Don't ends with java.io.File.separator)
launcher.info.switch_working_directory.content=We detected unexpected content in .minecraft%1$sversions%1$s%2$s. It's likely you selected "Isolated" mode, but it was switched to "Default" mode automatically or manually. The choice to readjust to "Isolated" mode is available to you.\nRe-adjust to 'Isolated' mode and make it effective for this launch, press "Yes". if you want to retain current version settings, press "No". if you want make it effective for this launch only, press "This launch only".
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Suggested change
launcher.info.switch_working_directory.content=We detected unexpected content in .minecraft%1$sversions%1$s%2$s. It's likely you selected "Isolated" mode, but it was switched to "Default" mode automatically or manually. The choice to readjust to "Isolated" mode is available to you.\nRe-adjust to 'Isolated' mode and make it effective for this launch, press "Yes". if you want to retain current version settings, press "No". if you want make it effective for this launch only, press "This launch only".
launcher.info.switch_working_directory.content=Existing game files were detected in ".minecraft%1$sversions%1$s%2$s", but the Working Directory is currently set to "Default".\n\nTo use these files, the setting in "Game Settings → Working Directory" should be "Isolated". Would you like to switch to Isolated mode?

Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

日语目前缺乏维护。如果没法做进一步校对的话,可以先回退,之后再处理。

launcher.crash.java_internal_error=Hello Minecraft! Launcher 由於目前 Java 損壞而無法繼續執行。請移除目前 Java,點擊 <a href="https://bell-sw.com/pages/downloads/#downloads">此處</a> 安裝合適的 Java 版本。
launcher.crash.hmcl_out_dated=Hello Minecraft! Launcher 遇到了無法處理的錯誤。已偵測到你的啟動器不是最新版本,請更新後重試!
launcher.update_java=請更新你的 Java
launcher.info.switch_working_directory.title=是否要切換工作目錄?
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Suggested change
launcher.info.switch_working_directory.title=是否要切換工作目錄?
launcher.info.switch_working_directory.title=偵測到實例檔案

launcher.update_java=請更新你的 Java
launcher.info.switch_working_directory.title=是否要切換工作目錄?
# %1$s = java.io.File.separator, %2$s = version root (Don't ends with java.io.File.separator)
launcher.info.switch_working_directory.content=我們在 .minecraft%1$sversions%1$s%2$s 中偵測到意外的內容。您可能選擇了「隔離」模式,但該模式已被自動或手動切換為「預設」模式。您現在可以重新調整為「隔離」模式。\n若想重新調整為「隔離」模式並在本次啟動中生效,請按「是」;若想保留目前版本設定,請按「否」;若想僅對本次啟動生效,請按「僅本次啟動」。
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Suggested change
launcher.info.switch_working_directory.content=我們在 .minecraft%1$sversions%1$s%2$s 中偵測到意外的內容。您可能選擇了「隔離」模式,但該模式已被自動或手動切換為「預設」模式。您現在可以重新調整為「隔離」模式。\n若想重新調整為「隔離」模式並在本次啟動中生效,請按「是」;若想保留目前版本設定,請按「否」;若想僅對本次啟動生效,請按「僅本次啟動」。
launcher.info.switch_working_directory.content=在「.minecraft%1$sversions%1$s%2$s」中偵測到既有遊戲檔案,但目前執行路徑設定為「預設」。\n\n要使用這些檔案,請在「(全域/實例特定) 遊戲設定 → 執行路徑」中選取「各實例獨立」。你是否要切換到「各實例獨立」模式?

launcher.crash.java_internal_error=Hello Minecraft! Launcher 由于当前 Java 损坏而无法继续运行。请卸载当前 Java,点击 <a href="https://bell-sw.com/pages/downloads/#downloads">此处</a> 安装合适的 Java 版本。
launcher.crash.hmcl_out_dated=Hello Minecraft! Launcher 遇到了无法处理的错误。已检测到你的启动器不是最新版本,请更新后再试。
launcher.update_java=请更新你的 Java。\n你可以访问 https://docs.hmcl.net/help.html 页面寻求帮助。
launcher.info.switch_working_directory.title=是否要切换工作目录?
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Suggested change
launcher.info.switch_working_directory.title=是否要切换工作目录?
launcher.info.switch_working_directory.title=检测到实例文件

launcher.update_java=请更新你的 Java。\n你可以访问 https://docs.hmcl.net/help.html 页面寻求帮助。
launcher.info.switch_working_directory.title=是否要切换工作目录?
# %1$s = java.io.File.separator, %2$s = version root (Don't ends with java.io.File.separator)
launcher.info.switch_working_directory.content=我们在 .minecraft%1$sversions%1$s%2$s 中检测到意外的内容。您可能选择了“隔离”模式,但该模式已被自动或手动切换为“默认”模式。您现在可以重新调整为“隔离”模式。\n若想重新调整为“隔离”模式并在本次启动中生效,请按“是”;若想保留当前版本设置,请按“否”;若想仅对本次启动生效,请按“仅本次启动”。
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Suggested change
launcher.info.switch_working_directory.content=我们在 .minecraft%1$sversions%1$s%2$s 中检测到意外的内容。您可能选择了“隔离”模式,但该模式已被自动或手动切换为“默认”模式。您现在可以重新调整为“隔离”模式。\n若想重新调整为“隔离”模式并在本次启动中生效,请按“是”;若想保留当前版本设置,请按“否”;若想仅对本次启动生效,请按“仅本次启动”。
launcher.info.switch_working_directory.content=在“.minecraft%1$sversions%1$s%2$s”中检测到既有游戏文件,但目前“版本隔离”设置为“默认”。\n\n要使用这些文件,请在“(全局/实例特定) 游戏设置 → 版本隔离”中选择“各实例独立”。\n\n你是否要切换到“各实例独立”模式?

Copy link
Member

@burningtnt burningtnt left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

显然你关闭了根本没解决的问题。此外,如果你不了解相关语言,请不要翻译非完全支持语言(比如日语)

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

4 participants